import { Filter } from "@nutui/icons-react-taro";
import { Button, Calendar, Cell } from "@nutui/nutui-react-taro";
import { useState } from "react";

const FormCalendar = ({ onConfirm, title }) => {
  const [date, setDate] = useState([]);
  const [isVisible, setIsVisible] = useState(false);

  const openSwitch = () => {
    setIsVisible(true);
  };

  const closeSwitch = () => {
    setIsVisible(false);
  };

  const setChooseValue = (param) => {
    console.log("paramparamparam", [...[param[0][3], param[1][3]]]);
    setDate([...[param[0][3], param[1][3]]]);
    onConfirm?.([...[param[0][3], param[1][3]]]);
  };

  // const select = (param) => {
  //   console.log(param);
  // };

  return (
    <>
      <Button fill="none" icon={<Filter />} onClick={openSwitch}></Button>

      <Calendar
        visible={isVisible}
        defaultValue={date}
        type="range"
        onClose={closeSwitch}
        onConfirm={setChooseValue}
        startDate="2022-12-22"
        title={title}
        // onDayClick={select}
      />
    </>
  );
};
export default FormCalendar;
